app.controller("reviseController",function($scope, $http,$routeParams){
    $scope.pact_id=$routeParams.id;
    console.log($scope.pact_id)
    $http({
        method: 'POST',
        url: '/OA/enrolone2one/list ',
        data:$.param({pact_id:$scope.pact_id}),
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).success(function (response) {
        console.log(response);
        $scope.enrol_datas = response.data;
        $scope.prods=$scope.enrol_datas;
        // 定义一个单击删除按钮时触发的事件，用于删除选中行
        $scope.delete = function($index){
            if ($index>=0) {
                console.log($scope.prods[$index])
                if(confirm("是否删除"+$scope.prods[$index].sn+"的排课么") ){
                    $http({
                        method:"POST",
                        url:'/OA/enrolone2one/delete ',
                        data:$.param({id:$scope.prods[$index].id}),
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                    }).success(function (result) {
                        if(result.ok==true){
                            $scope.prods.splice($index,1);
                        }else if(result.ok==false){
                            alert("删除失败，请重新删除")
                        }

                    })
                }
            };
        }
        // 定义一个申请按钮时触发的事件
        $scope.enrolapply = function($index){
            if ($index>=0) {
                console.log($scope.prods[$index])
                if(confirm("是否提交"+$scope.prods[$index].sn+"报课单") ){
                    $http({
                        method:"POST",
                        url:'/OA/enrolone2one/apply',
                        data:$.param({id:$scope.prods[$index].id}),
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                    }).success(function (result) {
                        if(result.ok==true){
                            alert("申请已提交！")
                            window.location.reload()
                        }else if(result.ok==false){
                            alert("申请失败，请重新申请！")
                        }

                    })
                }
            };
        }
        // 定义一个空对象 , 用于更新和保存数据时临时存储
    })
    // 退课单列表;
        $http({
            method:"POST",
            url:"/OA/dropone2one/list",
            data:$.param({pact_id:$scope.pact_id}),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (response){
            console.log(response)
            $scope.drop_datas  = response.data;
            $scope.arrs=$scope.drop_datas;
            // 定义一个单击删除按钮时触发的事件，用于删除选中行
            $scope.dropdelete = function($index){
                if ($index>=0) {
                    if(confirm("是否删除此条记录") ){
                        $http({
                            method:"POST",
                            url:'/OA/dropone2one/delete ',
                            data:$.param({id:$scope.arrs[$index].id}),
                            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                        }).success(function (result) {
                            if(result.ok==true){
                                $scope.arrs.splice($index,1);
                            }else{
                                alert("删除失败，请检查数据！")
                            }
                        })
                    }
                };
            }
            $scope.dropapply = function($index){
                if ($index>=0) {
                    if(confirm("是否提交此条申请记录") ){
                        $http({
                            method:"POST",
                            url:'/OA/dropone2one/apply ',
                            data:$.param({id:$scope.arrs[$index].id}),
                            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                        }).success(function (result) {
                            if(result.ok==true){
                                setTimeout(function () {
                                    window.location.reload()
                                },1)
                            }else{
                                alert("申请失败,请重新申请!")
                            }
                        })
                    }
                };
            }
        })
    // 补交单列表;
    $http({
        method:"POST",
        url:"/OA/mend/list",
        data:$.param({pact_id:$scope.pact_id}),
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).success(function (response){
        console.log(response)
        $scope.mend_datas = response.data;
        $scope.mend_apply = function($index){
            if ($index>=0) {
                if(confirm("是否提交此条申请记录") ){
                    $http({
                        method:"POST",
                        url:'/OA/mend/apply ',
                        data:$.param({id:$scope.mend_datas[$index].id}),
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                    }).success(function (result) {
                        if(result.ok==true){
                            setTimeout(function () {
                                window.location.reload()
                            },1)
                        }else if(result.ok==false){
                            alert(result.message)
                        }
                    })
                }
            };
        }
    })
    // 学员信息展示
        $http({
            method:"POST",
            url:"/OA/one2one/query ",
            data:$.param({id:$scope.pact_id}),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (response){
            $scope.findstudent=response.data;
            console.log($scope.findstudent)
            $("#saleone2one").find("option[value="+ $scope.findstudent.sale_id+"]").attr("selected","selected");
            $scope.submit=function () {
               var campus_id=$("#schoolcampus").find("option:selected").val();
               $scope.id=$scope.findstudent.student_id;
               $http({
                   method:"POST",
                   url:"/OA/student/update?is_from=1",
                   data:$.param({campus_id:campus_id,id:$scope.id}),
                   headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
               }).success(function (response) {
                   if(response.ok==true){
                       alert("调拨成功！")
                   }
               })
            }
            $scope.onetoonesubmit=function () {
                var sale_id=$("#saleone2one").find("option:selected").val();
                var sale_name=$("#saleone2one").find("option:selected").text();
                var sale_hour=$("#saleone2one").find("option:selected").attr("data");
                var id=$scope.pact_id;
                $scope.json={id:id,sale_id:sale_id,sale_name:sale_name,sale_hour:sale_hour};
                console.log($scope.json);
                $http({
                    method:"POST",
                    url:"/OA/one2one/update",
                    data:$.param($scope.json),
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                }).success(function (response) {
                        console.log(response)
                        alert("提交成功！");
                    setTimeout(function () {
                        window.location.reload()
                    },600)

                })
            }
        })
})

